from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html")
bsObj = BeautifulSoup(html, "html.parser")
print(bsObj.h1)
print(bsObj.html.body.h1)#与上相同
print(bsObj.html.head.h1)#head下不存在h1标签，返回None

bsObj = BeautifulSoup(html.read(), "html.parser")
print(bsObj.h1)
# print(bsObj.html.body.h1)#与上相同
# print(bsObj.html.head.h1)#head下不存在h1标签，返回None